package logic

import (
	"context"
	"time"
	"wx/cache"
	"wx/models/mysql"

	"wx/wxrpc/internal/svc"
	"wx/wxrpc/wxrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PyqAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPyqAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PyqAddLogic {
	return &PyqAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PyqAddLogic) PyqAdd(in *wxrpc.PyqAddRequest) (*wxrpc.PyqAddResponse, error) {
	// todo: add your logic here and delete this line
	pyq := mysql.Pyq{
		Title: in.Title,
		Text:  in.Text,
	}
	mysql.DB.Debug().Create(&pyq)
	cache.Rdb.Set(l.ctx, "pyq", pyq, time.Minute*5)

	return &wxrpc.PyqAddResponse{
		PyqId: int64(pyq.ID),
	}, nil
}
